﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'ReporteGraficaOrdenCompra')
	BEGIN
		DROP  Procedure  ReporteGraficaOrdenCompra
	END

GO

CREATE Procedure ReporteGraficaOrdenCompra

	(
		@fechainicio datetime,
		@fechafin datetime
	)


AS
begin
SELECT     dbo.Bien.Nombre,
           SUM(dbo.DetalleOrdenCompra.Cantidad) as 'Cantidad',
          DATENAME(month,OrdenCompra.FechaCompra)as 'Mes'
           
FROM       dbo.DetalleOrdenCompra INNER JOIN
           dbo.OrdenCompra ON dbo.DetalleOrdenCompra.IdOrdenCompra = dbo.OrdenCompra.IdOrdenCompra INNER JOIN
           dbo.Bien ON dbo.DetalleOrdenCompra.IdBien = dbo.Bien.IdBien
           where dbo.OrdenCompra.FechaCompra between @fechainicio and @fechafin
           group by dbo.Bien.Nombre, OrdenCompra.FechaCompra
end

GO


GRANT EXEC ON ReporteGraficaOrdenCompra TO PUBLIC

GO

